// 打包ES模块所用的配置文件
import { fileURLToPath, URL } from 'node:url'
import { resolve, dirname } from "node:path"
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

const __dirname = dirname(fileURLToPath(import.meta.url));

// https://vitejs.dev/config/
export default defineConfig({
    base: "/test_project/xq-element",
    server: {
        port: "1024",
        open: true,
        host: true
    },
    plugins: [
        vue(),
        vueJsx(),
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url))
        }
    },
    publicDir: "empty",
    build: {
        outDir: "dist/es",
        lib: {
            entry: resolve(__dirname, 'src/bundle.js'),
            name: "XiaoQuan-Element",
            fileName: "xiaoquan-element",
            formats: ['es']
        },
        // vite 内部使用的是 rollup 进行打包
        // rollupOptions 可以书写 rollup 的配置
        rollupOptions: {
            // 依赖不需要打包
            external: [
                'vue',
                '@fortawesome/fontawesome-svg-core',
                '@fortawesome/free-solid-svg-icons',
                '@fortawesome/vue-fontawesome',
                '@popperjs/core',
                'lodash-es'
            ]
        }
    }
})
